package org.tio.sitexxx.web.server.controller.minip;

import org.tio.http.server.annotation.RequestPath;
import org.tio.sitexxx.service.model.main.Commodity;
import org.tio.sitexxx.service.service.qj.CommodityService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestPath("/commodity")
public class CommodityController {
    /**
     * 返回小程序关联的商家的商品列表  本人仅仅提供注释
     * @param pageNum
     * @param priceRange
     * @param type
     * @param styles
     * @return
     */
    @RequestPath("/list")
    public Map<String,Object> list(Integer pageNum, String priceRange, String type, String styles){
        System.out.println("called");
        Map<String,Object> resultMap = new HashMap<>();
        //当字符串为“”时取null为值
        Map<String,Object> param = new HashMap<>();
        System.out.println(priceRange==null);
        if(priceRange!=null){
            param.put("priceRange",priceRange);
        }
        if(pageNum!=null){
            param.put("pageNum",pageNum*12);
        }else return null;
        if (type != null) {
            param.put("type",type.equals("")?null:type);
        }
        if(styles!=null){
            param.put("styles",styles.equals("")?null:styles);
        }
        List<Commodity> Commodity = CommodityService.me.getCommoditys(param);
        resultMap.put("ok",1);
        resultMap.put("msg",Commodity);
        return resultMap;
    }
}
